import { createStore } from "vuex";
import createPersistedState from "vuex-persistedstate";
import {time} from "echarts/core";

const store = createStore({
  state: {
    //状态存储器
    user: {
    }, //存储登录用户信息
    admin: "", //存储登录管理员信息
    count: 0, //计数器
  },
  mutations: {
    //自定义函数，用来修改状态存储器中的属性
    increment(state) {
      state.count++; //每触发一次increment,count+1
    },
    saveUser(state, option) {
      state.user = option;
    },
    loginOut(state) {
      state.user = "";
    },
    saveuser(state, option) {
      state.admin = option;
    },
  },
  plugins: [
    createPersistedState({
      storage: window.sessionStorage,
      reducer(val) {
        console.log(val,"gedfg")
        return {
          // 只存储state中的userData

          userData: val.user,
          time: 1000,
        }

      }



    }),
  ],
});

//提供外部引用的名称
export default store;
